#! /bin/sh

DEVICE_NAME="u-blox GPS receiver"
MODULE_NAME="e581.ko"
CDEV_NAME="/dev/e581"
MINOR=0

############ 确定用户具有管理员权限
find_user()
{
    user=$1
}
find_who()
{
    WHO=`who`
    find_user WHO
    if [ $user != root ]
    then
	echo "please switch user to root!"
	exit 1
    else
	SUDO=
    fi
}

# 插入驱动模块
which sudo > /dev/null
if [ $? == 0 ]
then
    SUDO=sudo
else
    find_who
fi
$SUDO insmod $MODULE_NAME
if [ $? != 0 ]
then
    echo "error when insert driver module"
    exit 1
fi

# 检查主设备号
fix_major()
{
    MAJOR=$1
}
MAJOR=`grep "$DEVICE_NAME" /proc/devices`
fix_major $MAJOR
$SUDO mknod $CDEV_NAME c $MAJOR $MINOR
if [ $? != 0 ]
then
    echo "error when make device node"
    exit 1
fi
